package exercise8;

import java.text.DateFormat;
import java.text.ParseException;

public class Employee extends Person {
	class Date{
		private int year;
		private int mouth;
		private int day;
		
		public Date(int year, int mouth, int day) {
			super();
			this.year = year;
			this.mouth = mouth;
			this.day = day;
		}
		
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + day;
			result = prime * result + mouth;
			result = prime * result + year;
			return result;
		}
		
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Date other = (Date) obj;
			if (day != other.day)
				return false;
			if (mouth != other.mouth)
				return false;
			if (year != other.year)
				return false;
			return true;
		}
		
		@Override
		public String toString() {
			return ""+year + "/" + mouth + "/" + day;
		}
		
		private Employee getOuterType() {
			return Employee.this;
		}
		
	}
	protected double salary;
	protected Date hireDay;
	public Employee(String name,double salary,int year,int month,int day) {
		super(name);
		this.salary = salary;
		this.hireDay = new Date(year,month,day);
		// TODO Auto-generated constructor stub
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((hireDay == null) ? 0 : hireDay.hashCode());
		long temp;
		temp = Double.doubleToLongBits(salary);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Employee other = (Employee) obj;
		if (hireDay == null) {
			if (other.hireDay != null)
				return false;
		} else if (!hireDay.equals(other.hireDay))
			return false;
		if (Double.doubleToLongBits(salary) != Double.doubleToLongBits(other.salary))
			return false;
		return true;
	}
	
	public Date getHairDay() {
		return hireDay;
	}

	public double getSalary() {
		return salary;
	}
	
	public String getDescription()
	{
		return this.getName()+",an employee with a salary of $"+String.format("%.2f", this.salary);
	}
	public void raiseSalary(double raisesalary) {
		@SuppressWarnings("unused")
		double salary=this.getSalary()+raisesalary;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		try {
			return "Employee [name="+this.getName()+",salary="+this.salary+",hairDay="+DateFormat.getDateInstance(DateFormat.SHORT).parse(hireDay.toString())+"]";
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
}
